package com.tangguo.vshop.domain;
/**
 * 订单
 * @author doonly
 *
 */

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.mongodb.core.mapping.DBRef;

public class Order extends BaseEntity{
	@DBRef private Mainbody mainbody;
	private Customer customer;
	private String code;
	@DBRef private User creator;
	private Double totalAmount;
	private List<OrderItem>orderDetails = new ArrayList<>();

	public Mainbody getMainbody() {
		return mainbody;
	}
	public void setMainbody(Mainbody mainbody) {
		this.mainbody = mainbody;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public List<OrderItem> getOrderDetails() {
		return orderDetails;
	}
	public void setOrderDetails(List<OrderItem> orderDetails) {
		this.orderDetails = orderDetails;
	}
	public User getCreator() {
		return creator;
	}
	public void setCreator(User creator) {
		this.creator = creator;
	}
	public Double getTotalAmount() {
		return totalAmount;
	}
	public void setTotalAmount(Double totalAmount) {
		this.totalAmount = totalAmount;
	}
	public void calculateTotalAmount() {
		totalAmount = 0.0;
		for(OrderItem item:orderDetails){
			totalAmount+=item.getPrice()*item.getQty();
		}
	}
}
